﻿using Inovout.Gis;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.DataSourcesGDB;

namespace Inovout.ArcGis
{
    public class ArcGisSessionFactory : IGisSessionFactory
    {
        private ArcGisConfiguration config;
        internal ArcGisConfiguration Configuration
        {
            get { return config; }
        }
        public ArcGisSessionFactory(ArcGisConfiguration config)
        {
            this.config = config;
        }
        public IGisSession OpenSession()
        {
            return new ArcGisSession(this);
        }
        internal IWorkspace Workspace
        {
            get { return GetWorksapce(); }
        }
        private IWorkspace GetWorksapce()
        {
            IWorkspaceFactory workspaceFactory;
            switch (config.Properties[GisEnvironment.DatabaseTypeName])
            {
                case "Access":
                    workspaceFactory = new AccessWorkspaceFactoryClass();
                    break;
                default:
                    throw new System.NotImplementedException(config.Properties[GisEnvironment.DatabaseTypeName]);
            }
            IPropertySet dbPropertySet = new PropertySet();
            dbPropertySet.SetProperty("DATABASE", config.Properties[GisEnvironment.AccessFileName]);

            return workspaceFactory.Open(dbPropertySet, 0);
        }

 
    }
}
